package com.pfsoft.transactiontest.service.impl;

import com.pfsoft.transactiontest.model.Person;
import com.pfsoft.transactiontest.repository.PersonRepository;
import com.pfsoft.transactiontest.service.PersonManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class PersonServiceImpl implements PersonManService {

    @Autowired
    private PersonRepository personRepository;

    @Transactional
    @Override
    public void personSave() throws Exception {
        Person person1=new Person();
        person1.setAge(999);
        person1.setName("rb");
        personRepository.saveAndFlush(person1);

        Person person2=new Person();
        RoleManService roleManService=new RoleManService();
        person2.setAge(roleManService.sum(3,4));
        person2.setName("pf");
         personRepository.saveAndFlush(person2);
    }
}
